<HTML><HEAD><TITLE>session_rollback(++Session)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">library(dbi)</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>session_rollback(++Session)</H1>
rollback transactional changes made to the database.
<DL>
<DT><EM>Session</EM></DT>
<DD>A session handle
</DD>
</DL>
<H2>Description</H2>
<P>
  This undoes all <STRONG>transactional</STRONG> changes made to the database since the last
  commit for this session. Note some DBMS can operate non-transactionally
  (for example, non-transactional tables in MySQL), such operations cannot
  be undone. Also, even for transactions, not all changes can be undone.
  See DBMS's manual for details.
</P><P>
  Outside a transaction this predicate will either succeed if rollback was
  successful, or raise an error otherwise.
<P></P>
  When executed within the scope of a session_transaction/2 goal, this 
  predicate will simply abort the complete outer transaction.
</P><P>
 NOTE: This predicate behaves very differently, depending on
 whether it is in a transaction or not. It is always advisable not
 to rely on it succeeding, but rather to fail or abort immediately
 after it adopting a coding style that causes a Prolog failure
 whenever a transaction cannot be completed.
<H3>Exceptions</H3>
<DL>
<DT><EM>(5) type error </EM>
<DD>Session is not a valid session handle
<DT><EM>(dbi_error) </EM>
<DD>Problems from DBMS during rollback.
</DL>
<H2>Examples</H2>
<PRE>
    session_sql(Session, "insert into mytable values ('a')", _),
    session_commit(Session), % committing the insert of a to table mytable 
    session_sql(Session, "insert into mytable values ('b')", _),
    session_sql(Session, "insert into mytable values ('c')", _),
    % undo the inserting of b and c into table mytable (if tranactional)
    session_rollback(Session), 
</PRE>
<H2>See Also</H2>
<A HREF="../../lib/dbi/session_commit-1.html">session_commit / 1</A>, <A HREF="../../lib/dbi/session_transaction-2.html">session_transaction / 2</A>
</BODY></HTML>
